package Unicart.applogic3;

import org.openqa.selenium.WebDriver;

import Unicart.applogic.ApplicationManager;
import Unicart.applogic.ItemHelper;
import Unicart.applogic.UserHelper;
import Unicart.applogic.NavigationHelper;
import Unicart.util.Browser;
import Unicart.util.PropertyLoader;
import Unicart.webdriver.WebDriverFactory;

public class ApplicationManager3 implements ApplicationManager {
	
	private UserHelper userHelper;
	private ItemHelper itemHelper;
	private NavigationHelper navHelper;

	private WebDriver driver;
	private String baseUrl;
	private String orderAdminUrl;
	
	public ApplicationManager3() {
		baseUrl = PropertyLoader.loadProperty("site.url");
		orderAdminUrl = PropertyLoader.loadProperty("admin.url");
		String gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

		Browser browser = new Browser();
		browser.setName(PropertyLoader.loadProperty("browser.name"));
		browser.setVersion(PropertyLoader.loadProperty("browser.version"));
		browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

		String username = PropertyLoader.loadProperty("user.username");
		String password = PropertyLoader.loadProperty("user.password");
		
		driver = WebDriverFactory.getInstance(gridHubUrl, browser, username,
				password);
		//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		
		userHelper = new UserHelper3(this);
		itemHelper = new ItemHelper3(this);
		navHelper = new NavigationHelper3(this);
		
		getNavigationHelper().openMainPage();
	}
	
	
	@Override
	public UserHelper getUserHelper() {
	    return userHelper;
	}

	@Override
	public ItemHelper getItemHelper() {
	    return itemHelper;
	}
	
	@Override
	public NavigationHelper getNavigationHelper() {
	    return navHelper;
	}

	protected WebDriver getWebDriver() {
	    return driver;
	}

	protected String getBaseUrl() {
	    return baseUrl;
	}
	
	protected String getOrderAdminUrl() {
	    return orderAdminUrl;
	}
	
	@Override
	  	public void stop() {
	    	if (driver != null) {
	    		driver.quit();
	    }
	}
	
}